#endcoding:utf-8
class CounselorInfosController < ApplicationController
  before_action :logged_in?
  layout "user"
  def new
    @info = CounselorInfo.new
  end
  def edit
    @info = CounselorInfo.find_by_user_id(params[:id])
    if !@info
      redirect_to new_counselor_info_path
    end
  end
  def create
    @info = CounselorInfo.new(info_params)
    if @info.save
      flash[:success] = "编辑成功"
      redirect_to "/myinfo"+uid
    else
      flash[:success] = "编辑失败"
      redirect_to "/editinfo"
    end
  end
  def update
    @info  = CounselorInfo.find(infoid)
    if @info.update(info_params)
      flash[:success] = "保存成功"
      redirect_to "/myinfo/"+uid
    else
      flash[:danger] = "保存失败"
      @errors = @info.errors.full_messages
      render "/editinfo"
    end
  end
  private
  def info_params
    params[:counselor_info].store('user_id',uid)
    params.require(:counselor_info).permit(:real_name,:phone,:user_id,:good_at)
  end
end
